//
//  MSCollectionBtn.m
//  WeShare2.0
//
//  Created by Mac_User on 15/11/3.
//  Copyright (c) 2015年 WeShare. All rights reserved.
//

#import "MSCollectionBtn.h"

@implementation MSCollectionBtn
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    
        [self setImage:[UIImage imageNamed:@"collection_normal"] forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"collection_selected"] forState:UIControlStateSelected];
        [self addTarget:self action:@selector(collectionBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

- (void)setNormalImage:(UIImage *)normalImage
{
    _normalImage = normalImage;
     [self setImage:normalImage forState:UIControlStateNormal];
}


- (void)setSelectedImage:(UIImage *)selectedImage
{
    _selectedImage = selectedImage;
    [self setImage:selectedImage forState:UIControlStateSelected];
}
- (void)collectionBtnAction:(GXButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(collectionBtnAction:)])
    {
        [self.delegate collectionBtnAction:sender];
    }
    [self flip];
    
}

- (void)flip
{
    if (!self.isSelectedChanged) {
        self.selected = !self.selected;
        if (self.selected)
        {
            CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
            animation.duration = 0.4;
            NSMutableArray *values = [NSMutableArray array];
            [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
            [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
            [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
            [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
            animation.values = values;
            [self.layer addAnimation:animation forKey:nil];
        }
    }
  
    
}
@end
